package com.weareint.examples.dto;

import com.weareint.examples.entity.Company;
import com.weareint.common.dto.AbstractDTO;
import com.weareint.common.dto.IBasicDTO;
import com.weareint.common.utils.DateUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 *
 *
 * <pre>
 *      客户与供应商DTO
 * </pre>
 *
 * @author Auto Generator
 * @date 2021-07-16
 */
@ApiModel(value = "客户与供应商", description = "客户与供应商")
@Data
@EqualsAndHashCode(callSuper = true)
public class CompanyDTO extends AbstractDTO implements IBasicDTO<Company> {

    @ApiModelProperty(value = "公司名称")
    private String name;

    @ApiModelProperty(value = "公司编码")
    private String code;

    @ApiModelProperty(value = "状态: 0正常，1禁用")
    private Integer state;

    @ApiModelProperty(value = "联系人")
    private String contacts;

    @ApiModelProperty(value = "手机号")
    private String mobile;

    @ApiModelProperty(value = "备注")
    private String remark;

    @ApiModelProperty(value = "类型：0表示客户，1表示供应商")
    private Integer type;

    @ApiModelProperty(value = "")
    private Long materialId;

    @ApiModelProperty(value = "")
    private Long productId;


    /**
     * <pre>
     *     转化为Entity对象
     * </pre>
     * @return {@link Company}
     */
    @Override
    public Company toEntity() {
        Company entity = new Company();
        entity.setId(this.getId());
        entity.setName(this.getName());
        entity.setCode(this.getCode());
        entity.setState(this.getState());
        entity.setContacts(this.getContacts());
        entity.setMobile(this.getMobile());
        entity.setRemark(this.getRemark());
        entity.setType(this.getType());
        entity.setMaterialId(this.getMaterialId());
        entity.setProductId(this.getProductId());
        return entity;
    }

    /**
     * <pre>
     *     依据非空的属性创建一个新Entity
     * </pre>
     * @return {@link Company}
     */
    @Override
    public Company toNewEntityIgnoreNulls() {
        Company unPersistentEntity = new Company();
        toEntityIgnoreNulls(unPersistentEntity);
        return unPersistentEntity;
    }

    /**
     * <pre>
     *     把非空的属性复制到已有的实体上
     * </pre>
     * @param persistentEntity {@link Company}
     */
    @Override
    public void toEntityIgnoreNulls(Company persistentEntity) {
        if (null != this.getId()){
            persistentEntity.setId(this.getId());
        }
        if (null != this.getCreateTime()){
            persistentEntity.setCreateTime(DateUtil.parse(this.getCreateTime()));
        }
        if (null != this.getUpdateTime()){
            persistentEntity.setUpdateTime(DateUtil.parse(this.getUpdateTime()));
        }
        if (null != this.getCreator()){
            persistentEntity.setCreator(this.getCreator());
        }
        if (null != this.getUpdater()){
            persistentEntity.setUpdater(this.getUpdater());
        }
        if (null != this.getName()){
            persistentEntity.setName(this.getName());
        }
        if (null != this.getCode()){
            persistentEntity.setCode(this.getCode());
        }
        if (null != this.getState()){
            persistentEntity.setState(this.getState());
        }
        if (null != this.getContacts()){
            persistentEntity.setContacts(this.getContacts());
        }
        if (null != this.getMobile()){
            persistentEntity.setMobile(this.getMobile());
        }
        if (null != this.getRemark()){
            persistentEntity.setRemark(this.getRemark());
        }
        if (null != this.getType()){
            persistentEntity.setType(this.getType());
        }
        if (null != this.getMaterialId()){
            persistentEntity.setMaterialId(this.getMaterialId());
        }
        if (null != this.getProductId()){
            persistentEntity.setProductId(this.getProductId());
        }
    }


}
